﻿using System;
using System.Collections.Generic;
using System.Text;
using EasyStudy.Properties;
using System.Data;

namespace EasyStudy.Logic.Percentage
{
    public class PercentageDBMgr
    {
        public static Percentage DataRowToPercentage(DataRow dr)
        {   
            int totalTask = 0;
            int cur = 0;

            string subject = dr["SUBJECT"].ToString();
            string curIndex = dr["NEXT_INDEX"].ToString();
            cur = int.Parse(curIndex);
            string allDate = dr["REMIND_TIME_LIST"].ToString();
            string type = dr["CATEGORY"].ToString();
            totalTask = allDate.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length;

            return new Percentage(subject, type, cur, totalTask);
        }

        public static List<Percentage> GetAllProjectsPercentage()
        {
            List<Percentage> percentages = new List<Percentage>();
            Settings settings = new Settings();

            DataTable allData = EbbTaskDBMgr.dbHelper.ExecuteDataTable(settings.SqlGetAll, null);
            int totalTask = 0;
            int cur = 0;

            foreach (DataRow dr in allData.Rows)
            {
                string subject = dr["SUBJECT"].ToString();
                string curIndex = dr["NEXT_INDEX"].ToString();
                cur = int.Parse(curIndex);
                string allDate = dr["REMIND_TIME_LIST"].ToString();
                string type = dr["CATEGORY"].ToString();
                totalTask = allDate.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length;
                percentages.Add(new Percentage(subject, type, cur, totalTask));
            }


            return percentages;
        }
    }
}
